﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CSP.Model.Presenter;
using CSP.Model.Entities;
using System.Collections.Generic;

namespace eGov.SharePoint.MyPeeps.WebControls
{
    public partial class Following : System.Web.UI.UserControl, IFollowingPresenter
    {
        private FollowingPresenter presenter = null;
        protected global::System.Web.UI.WebControls.Repeater rptFollowing;

        protected global::System.Web.UI.WebControls.Label lblNofollowers;

        #region Public Properties

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                BindControl();

        }

        public void BindFollowing(List<UserColleague> colleagues)
        {
            try
            {
                rptFollowing.DataSource = colleagues;
                rptFollowing.DataBind();
            }
            catch
            {
                throw;
            }

        }

        public void BindControl()
        {
            try
            {
                presenter = new FollowingPresenter(this);

                presenter.Load();


                if (rptFollowing != null && rptFollowing.Items.Count < 1)
                    lblNofollowers.Visible = true;
                else
                {
                    lblNofollowers.Visible = false;
                }
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }

        }

        private void DisplayError(Exception ex)
        {
            this.Controls.Add(new LiteralControl("<div style='color:Red; display:none;'>" + ex.ToString() + "</div>"));
        }





        private void CheckForNewColleagues()
        {

        }
    }
}